package CutLoad.transitions.fireworks
{
	import CutLoad.Base;
	import CutLoad.cookies.RandNO;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class fireworksSome extends Base
	{
		private var timer:Timer;
		private var sWidth:Number,sHeight:Number;
		private var firesArray:Array;
		private static var colorArray:Array;
		public static function playSomeRandColor(w:Number,h:Number,count:Number,time:Number):fireworksSome{
			var arrColor:Array=new Array();
			for(var i:Number=0;i<count;i++){
				arrColor.push(RandNO.getRndColor24());
			}
			return new fireworksSome(w,h,count,time,arrColor);
		}
		public function fireworksSome(w:Number,h:Number,fireworksNum:Number,time:Number,colorArray:Array){
			sWidth=w;
			sHeight=h;
			fireworksSome.colorArray=colorArray;
			firesArray=new Array();
			for(var i:Number=0;i<fireworksNum;i++){
				var t:Number=Math.floor(Math.random()*(colorArray.length-1));
				firesArray[i]=new Fireworks(colorArray[t]);
				this.addChild(firesArray[i])
			}
			timer=new Timer(1000,time);
			timer.addEventListener(TimerEvent.TIMER,onEachSecond);
			timer.start();
		}
		private function onEachSecond(e:Event):void{
			for(var i:Number=0;i<firesArray.length;i++){
				if(!firesArray[i].bombing()){
					firesArray[i].reset();
					firesArray[i].x=Math.random()*sWidth;
					firesArray[i].y=Math.random()*sHeight;
					var t:Number=Math.round(Math.random()*12);
					firesArray[i].bomb(t);
				}
			}
		}
	}
}